{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def parse_file(filename):\n",
    "    cols = {}\n",
    "    with open(filename, 'r') as f:\n",
    "        lines = f.readlines()\n",
    "        for i in range(len(lines)):\n",
    "            words = lines[i].split()\n",
    "            if len(words) == 5:\n",
    "                if words[0] == 'BlockID':\n",
    "                    for word in words:\n",
    "                        cols[word] = []\n",
    "                    continue\n",
    "                else:\n",
    "                    cols['BlockID'].append(int(words[0]))\n",
    "                    cols['bct'].append(int(words[1]))\n",
    "                    cols['BlockSize'].append(int(words[2]))\n",
    "                    cols['Priority'].append(int(words[3]))\n",
    "                    cols['Deadline'].append(int(words[4]))\n",
    "            else:\n",
    "                continue\n",
    "    return cols\n",
    "\n",
    "def basic_stat(cols):\n",
    "    block_num = 0\n",
    "    block_num_1 = 0\n",
    "    block_num_2 = 0\n",
    "    TOTAL_BLOCK_NUM = 1063\n",
    "    TOTAL_BLOCK_NUM_1 = 703\n",
    "    TOTAL_BLOCK_NUM_2 = 360\n",
    "    for i in range(len(cols['BlockID'])):\n",
    "        block_num += 1\n",
    "        if cols['Priority'][i] == 1:\n",
    "            block_num_1 += 1\n",
    "        elif cols['Priority'][i] == 2:\n",
    "            block_num_2 += 1\n",
    "        else:\n",
    "            pass\n",
    "    print(block_num, block_num_1, block_num_2)\n",
    "    print(\"arrive rate: \", block_num_1 / TOTAL_BLOCK_NUM_1, block_num_2 / TOTAL_BLOCK_NUM_2)\n",
    "    return block_num, block_num_1, block_num_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "connection closed, recv=24403 sent=22714 lost=0 rtt=9.423340ms cwnd=14520, total_bytes=18851119, complete_bytes=12460885, good_bytes=12405225, total_time=20002546\n",
      "\n",
      "{'recv': '24403', 'sent': '22714', 'lost': '0', 'rtt': '9.423340', 'cwnd': '14520', 'total_bytes': '18851119', 'complete_bytes': '12460885', 'good_bytes': '12405225', 'total_time': '20002546'}\n"
     ]
    }
   ],
   "source": [
    "test_df = pd.DataFrame()\n",
    "logFileName = \"examples/dtp_test/client_200.log\"\n",
    "pattern = r\"[\\w ,]*recv=(?P<recv>\\d+) sent=(?P<sent>\\d+) lost=(?P<lost>\\d+) rtt=(?P<rtt>[\\d.]+)ms cwnd=(?P<cwnd>\\d+), total_bytes=(?P<total_bytes>\\d+), complete_bytes=(?P<complete_bytes>\\d+), good_bytes=(?P<good_bytes>\\d+), total_time=(?P<total_time>\\d+)\"\n",
    "with open(logFileName, \"r\") as logFile:\n",
    "    line = logFile.readlines()[-1]\n",
    "    print(line)\n",
    "    print(re.match(pattern, line).groupdict())"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
  },
  "kernelspec": {
   "display_name": "Python 3.8.10 64-bit",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
